function render(list) {
  let oBody = document.querySelector('tbody')
  for (let i in list) {
    let album = list[i]
    let operation = ''
    let cls = 'empty'
    if (album.state === '未发布') {
      cls = 'empty'
      operation = `<a href="/studio/album/publish.do?aid=${album.aid}">发布</a>`
    } else if (album.state === '已发布') {
      cls = 'published'
      operation = `<a href="/studio/album/withdraw.do?aid=${album.aid}">下线</a>`
    } else if (album.state === '已下线') {
      cls = 'withdrawn'
      operation = `<a href="/studio/album/publish.do?aid=${album.aid}">发布</a>`
    }

    let html = `<tr class="${cls}">
            <td>${album.aid}</td>
            <td><a href="/studio/album/relate.html?aid=${album.aid}">${album.title}</a></td>
            <td><img src="${album.cover}"></td>
            <td>${album.count}</td>
            <td>${album.state}</td>
            <td>${operation}</td>
          </tr>`
    oBody.innerHTML += html
  }
}

window.addEventListener('load', function () {
  let xhr = new XMLHttpRequest()
  xhr.open('get', '/studio/album/list.json')
  xhr.addEventListener('load', function () {
    console.log(xhr.responseText)
    let data = JSON.parse(this.responseText)
    renderCurrentUser(data.currentUser)
    if (data.albumList) {
      render(data.albumList)

    }
  })
  xhr.send()
})